import { Component, OnInit, ViewChild, Input } from '@angular/core';
import { STColumn } from '@delon/abc';
import { GridComponent, SupDic, HttpService } from 'lbf';
import { SFSchema, SFComponent } from '@delon/form';
import { NzMessageService } from 'ng-zorro-antd';

@Component({
  selector: 'app-lb-bzbq',
  templateUrl: './lb-bzbq.component.html',
  styleUrls: ['./lb-bzbq.component.less']
})
export class LbBzbqComponent implements OnInit {

  @ViewChild('st', { static: true }) st: GridComponent;
  @ViewChild('pop', { static: false }) pop: SFComponent;

  @Input() param: any;

  isVisible = false;
  addFormData = {};

  params = {
    sname: 'query_bzbq',
    form: {},
  };

  columns: STColumn[] = [
    { title: '材料名称', index: 'STUFFNAME' },
    { title: '材料类型', index: 'STUFFTYPE' },
    { title: '材料唯一ID', index: 'STUFFUNIID' },
    { title: '收取方式', index: 'FETCHMODE' },
    { title: '材料数量', index: 'STUFFNUM' },
    { title: '附件名称', index: 'ATTACHNAME' },
    { title: '附件存储路径', index: 'ATTACHPATH' },
    { title: '备注信息', index: 'MEMO' },
    {
      title: '操作区',
      width: '50px',
      fixed: 'right',
      buttons: [
        {
          text: '修改',
          click: (record: any) => this.del(record),
        },
      ],
    },
  ];


  newSchema: SFSchema = {
    properties: {
      PROJID: {
        type: 'string',
        title: '办件号',
        readOnly: true,
      },
      STUFFINFOS: {
        type: 'string',
        title: '材料id',
        readOnly: true,
      },
      STUFFNAME: {
        type: 'string',
        title: '材料名称',
        readOnly: true,
      },
      STUFFTYPE: {
        type: 'string',
        title: '材料类型',
        //enum: this.supdic.getSFDic('STUFFTYPE'),
        readOnly: true,
      },
      FETCHMODE: {
        type: 'string',
        title: '收取方式',
        readOnly: true,
      },
      STUFFNUM: {
        type: 'number',
        title: '材料数量',
        readOnly: true,
      },
      MEMO: {
        type: 'string',
        title: '备注信息',
      },
    },
    required: ["MEMO"]
  };


  constructor(private supdic: SupDic, public msgSrv: NzMessageService, private lbs: HttpService, ) { }

  ngOnInit() {
    this.params.form = { PROJID: this.param };
    this.query();
  }


  query() {
    this.st.reload();
  }

  del(record: any) {

    this.pop.formData = record;
    this.pop.reset();
    this.isVisible = true;
    /*
        this.lbs.lbservice('del_bzcl', { para: record }).then(resdata => {
          if (resdata.code < 1) {
            this.msgSrv.error(resdata.errmsg);
          }
          else {
            this.query();
          }
        })*/
  }

  add() {
    this.pop.formData =
      this.pop.setValue('/PROJID', this.param);
    this.isVisible = true;
  }


  handleCancel() {
    this.isVisible = false;
  }

  handleOk() {
    alert(this.param)
  }

  xz() {
    if (!this.pop.valid) {
      this.msgSrv.error('必填项不能为空！');
      return;
    }

    this.lbs.lbservice('add_bzcl', { para: this.pop.value }).then(resdata => {
      if (resdata.code < 1) {
        this.msgSrv.error(resdata.errmsg);
      }
      else {
        this.isVisible = false;
        //this.addFormData = { PROJID: this.param };
        this.query();
      }

    })

  }

}
